package com.kevin.kitchenshow2.entity;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.w3c.dom.Node;

import com.kevin.kitchenshow2.KitchenShow;
import com.kevin.kitchenshow2.R;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

public class Category {
	private Drawable image;
	private String name;
	private String id;
	private Node xmlNode;
	private Boolean isLoadSub;
	private List<SubCategory> lstSubCategory;
	private Context context;

	public Category() {

	}

	public Category(Node node, Context context) {
		xmlNode = node;
		this.context = context;
		name = KitchenShow.getAttibuteOfNode(xmlNode, "name");
		id = KitchenShow.getAttibuteOfNode(xmlNode, "id");
		String url = KitchenShow.getAttibuteOfNode(xmlNode, "image");
		if (url != null) {
			try {
				URL rUrl = new URL(url);
				InputStream is = rUrl.openStream();
				image = Drawable.createFromStream(is, id);
				is.close();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				image = this.context.getResources().getDrawable(
						R.drawable.unkown);
			}
		}
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Boolean getIsLoadSub() {
		return isLoadSub;
	}

	public void setIsLoadSub(Boolean isLoad) {
		this.isLoadSub = isLoad;
	}

	public List<SubCategory> getLstSubCategory() {
		return lstSubCategory;
	}

	public void setLstSubCategory(List<SubCategory> lstSubCategory) {
		this.lstSubCategory = lstSubCategory;
	}

	public Drawable getImage() {
		return image;
	}

	public void setImage(Drawable image) {
		this.image = image;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Node getXmlNode() {
		return xmlNode;
	}

	public void setXmlNode(Node xmlNode) {
		this.xmlNode = xmlNode;
	}

}
